package org.mogoo.simple;

import org.apache.tomcat.dbcp.dbcp.BasicDataSource;

import java.sql.*;

/**
 * Created with IntelliJ IDEA.
 * Author: Fang
 * Date: 2012-08-20
 * Time: 14:03
 * Email: dongfang@mogoo.org
 */
public class DatabaseSimple
{
    public static void main(String[] args)
    {
        try
        {
            Class.forName("org.postgres.Driver");

            Connection ct = DriverManager.getConnection("url","user","password");
            PreparedStatement ps = ct.prepareStatement("");
            CallableStatement cs = ct.prepareCall("{call xxxx(2,3,3)}");
            ResultSet rs = ps.executeQuery();
            ResultSetMetaData rsmd = rs.getMetaData();
            rsmd.getColumnCount();
            rs.updateRow();

            //使用连接池获取Connection对象
            //数据源(dbs)无需创建多个,一个程序只有一个就行了.建议把它作为static变量,在程序初始化时创建.
            BasicDataSource bds = new BasicDataSource();
            bds.setDriverClassName("org.postgres.Driver");
            bds.setUrl("");
            bds.setUsername("");
            bds.setPassword("");
            bds.setInitialSize(5);
            bds.setMaxActive(10);
            bds.setMinIdle(2);
            Connection ct2 = bds.getConnection();

        }
        catch (ClassNotFoundException e)
        {
            e.printStackTrace();
        }
        catch (SQLException e)
        {
            e.printStackTrace();
        }

    }



}
